//
//  ButtonAndLabelView.m
//  uMeng
//
//  Created by ZhuoLaiQiang@Gmail.com on 11-6-4.
//  Copyright 2011年 Mtime. All rights reserved.
//

#import "ButtonAndLabelView.h"
#import "CONSTS.h"


@implementation ButtonAndLabelView

- (id)initWithButtonImage:(UIImage*)image buttonPressImage:(UIImage*)pressImage delegate:(id)delegate textOfLabel:(NSString*)text tagOfbutton:(int)tag
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
//#warning  这里还是改换成UIButtonTypeCustom,因为现在合适的图片，所以先暂时用UIButtonTypeRoundedRect
        _button = [UIButton buttonWithType: UIButtonTypeCustom];
        _button.frame = CGRectMake((btnWidth - 58.0) / 2, 0, 58.0, 62.0);
        _button.tag = tag;
        if (image) {
            [_button setBackgroundImage: image forState:UIControlStateNormal];
        }
        if (pressImage) {
            [_button setBackgroundImage: pressImage forState: UIControlStateHighlighted];
        }
        _delegate = delegate;
        [_button addTarget: _delegate action: @selector(btnPressed:) forControlEvents: UIControlEventTouchUpInside];
        [self addSubview: _button];
        
        _label = [[[UILabel alloc] initWithFrame: CGRectMake(0, 
                                                            _button.frame.size.height,
                                                            btnWidth, 
                                                            20)] autorelease];
        _label.backgroundColor = [UIColor clearColor];
        _label.text = text;
        _label.font = [UIFont systemFontOfSize: 13];
        _label.textColor = [UIColor whiteColor];
        _label.textAlignment = UITextAlignmentCenter;
        [self addSubview: _label];
    }
    return self;
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect
 {
 // Drawing code
 }
 */

- (void)dealloc
{
    [super dealloc];
}

@end
